

/*
ID: huangmingbo
LANG: JAVA
TASK: palsquare
*/

import java.io.*;

public class palsquare {

    public static void main(String[] args) throws IOException {
        try (
                BufferedReader reader = new BufferedReader(new InputStreamReader(palsquare.class.getResourceAsStream(palsquare.class.getSimpleName() + ".in")));
                PrintWriter writer = new PrintWriter(new FileWriter(palsquare.class.getSimpleName() + ".out"));
        ) {

            char[] base = new char[10 + 26];
            for (byte i = 0; i < 10; i++) {
                base[i] =  (char) ('0' + i);
            }

            for (char i = 'A'; i <= 'Z'; i++) {
                base[i - 'A' + 10] = i;
            }

            int baseB = Integer.parseInt(reader.readLine());
            String baseRet;
            for (int i = 1; i <= 300; i++) {
                baseRet = getpal(i * i, baseB, base);
                if (isPalSquare(baseRet)) {
                    writer.println(getpal(i, baseB, base) + " " + baseRet);
                }
            }
        }
    }

    private static boolean isPalSquare(String baseRet) {
        for (int i = 0; i < baseRet.length() / 2; i++) {
            if (baseRet.charAt(i) != baseRet.charAt(baseRet.length() - 1 - i)) {
                return false;
            }
        }

        return true;
    }

    private static String getpal(int i, int baseB, char[] base) {

        String t = "";
        while (i > 0) {
            t = base[i % baseB] + t;
            i = i / baseB;
        }

        return t;
    }
}
